use super::function_keys::{READ_FILE_KEY, WRITE_FILE_KEY};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use serde_json::json;

pub const TOOLS_JSON: Lazy<serde_json::Value> = Lazy::new(move || {
    json!([{
        "type": "function",
        "function": {
            "name": READ_FILE_KEY,
            "description": "读取文件，需要提供文件相对路径",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "文件的相对地址",
                    }
                },
                "required": ["file_path"]
            },
        }
    },
    {
        "type": "function",
        "function": {
            "name": WRITE_FILE_KEY,
            "description": "以覆盖的方式写入文件，如果文件不存在，会自动创建",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "文件的相对地址",
                    },
                    "content": {
                        "type": "string",
                        "description": "文件的文本内容",
                    }
                },
                "required": ["file_path", "content"]
            },
        }
        }
        ])
});

#[derive(Debug, Deserialize)]
pub struct ReadFileArgs {
    pub call_id: Option<String>,
    pub name: Option<String>,
    pub file_path: String,
}

#[derive(Debug, Deserialize)]
pub struct WriteFileArgs {
    pub call_id: Option<String>,
    pub name: Option<String>,
    pub file_path: String,
    pub content: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ToolResult {
    pub tool_call_id: String,
    pub name: String,
    pub content: String,
}

impl ToolResult {
    pub fn new(tool_call_id: String, name: String, content: &str) -> Self {
        Self {
            tool_call_id,
            name,
            content: content.to_string(),
        }
    }
}
